//
//  BaseViewController.m
//  HeJuBao
//
//  Created by chris on 15/10/28.
//  Copyright (c) 2015年 Chris. All rights reserved.
//

#import "BaseViewController.h"

#import "MyProgress.h"

@interface BaseViewController()

@property (nonatomic, retain) MyProgress * myProgressView;

@end

@implementation BaseViewController

-(void)startLoading{
    [self stopLoading];
    [self startMyProgress];
}

-(void)stopLoading{
    [self stopMyProgress];
}

-(void)startMyProgress{
    
    if (_myProgressView==nil){
        _myProgressView = [[[NSBundle mainBundle]loadNibNamed:@"MyProgress" owner:self options:Nil] objectAtIndex:0];
        _myProgressView.center=self.view.center;
        [self performSelector:@selector(showProgressDelay) withObject:nil afterDelay:0.3];
    }
}

-(void)stopMyProgress{
    
    if (_myProgressView != nil){
        [_myProgressView Hide];
        [_myProgressView removeFromSuperview];
        _myProgressView=nil;
    }
}

-(void)showProgressDelay{
    if (self.myProgressView!=nil){
        self.myProgressView.center = self.view.window.center;
        [self.view.window addSubview:self.myProgressView];
        [self.myProgressView Show];
    }
}

- (UIViewController *)appRootViewController
{
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *topVC = appRootVC;
    while (topVC.presentedViewController) {
        topVC = topVC.presentedViewController;
    }
    return topVC;
}

@end
